<?php
/**
 * Created by PhpStorm.
 * User: 847050412
 * Date: 2016/8/14
 * Time: 13:05
 */
class UserForm extends \Phalcon\Forms\Form {

    public function initialize() {

        // userName
        $username = new \Phalcon\Forms\Element\Text('username');

        $username->addValidators([
            new \Phalcon\Validation\Validator\PresenceOf([
                'message' => '用户名必填'
            ]),
            new \Phalcon\Validation\Validator\StringLength([
                'max'            => 16,
                'min'            => 6,
                'messageMaximum' => '已经超过做大字符16',
                'messageMinimum' => '最少6个字符'
            ])
        ]);

        $this->add($username);

        // Password
        $password = new \Phalcon\Forms\Element\Password('password');
        $password->addValidators([
            new \Phalcon\Validation\Validator\PresenceOf([
                'message' => '密码必填'
            ]),
            new \Phalcon\Validation\Validator\StringLength([
                'max'            => 16,
                'min'            => 6,
                'messageMaximum' => '密码已经超过16位',
                'messageMinimum' => '密码最少6位'
            ])
        ]);
        $this->add($password);
    }
}